class Solution {
public:
    void dfs(vector<string>& vecRet,int left,int right,int n,string cur){

        if(cur.size()==2*n){
            vecRet.push_back(cur);
            return;
        }
        if(left<n){
            dfs(vecRet,left+1,right,n,cur+"(");
        }
        if(right<left){
            dfs(vecRet,left,right+1,n,cur+")");
        }
    }
    vector<string> generateParenthesis(int n) {
        
        vector<string> vecRet;
        string cur;
        dfs(vecRet,0,0,n,cur);

        return vecRet;
    }
};
